package lg.minecraft.plugin.testeconomy.command;

import lg.minecraft.plugin.testeconomy.config.MessageConfig;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 * @author langle__
 * @version 1.0
 */
public class BalanceCommand extends SubCommand {

    @Override
    public String getName() {
        return "balance";
    }

    @Override
    public void onCommand(CommandSender sender, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            double balance = getStorage().getBalance(player);
            player.sendMessage(MessageConfig.getBalanceSuccess(balance));
        } else {
            if (args.length > 0) {
                Player player = Bukkit.getPlayer(args[0]);
                if (player == null) {
                    sender.sendMessage(MessageConfig.getPLAYER_NOT_FOUND());
                    return;
                }
                double balance = getStorage().getBalance(player);
                sender.sendMessage(MessageConfig.getBalanceOtherSuccess(player.getName(), balance));
            }
        }
    }

}
